﻿using Hr.DAL;
using Hr.IBLL;
using Hr.IDAL;
using Hr.Model;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Hr.BLL
{
    public partial class UserService:BaseService<User_List>,IUser_ListService
    {
        private IUser_ListDAL IUserList = Hr.DALContainer.Container.Resolve<IUser_ListDAL>();
        //引用自己的DAL层
        protected UserDAL UL1 = new UserDAL();

        /// <summary>
        /// 根据ID获取用户管理
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public User_List GetUserInfo(int id)
        {
            return UL1.GetUserInfo(id);//.GetModels(n => n.pk_User == id).SingleOrDefault();
            
        }

        /// <summary>
        /// 根据ID获取职位管理
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public User_Position GetPositionInfo(int id)
        {
            return UL1.GetPositionInfo(id);
        }

        /// <summary>
        /// 根据ID获取部门管理
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public User_Department GetDepartmentInfo(int id)
        {
            return UL1.GetDepartmentInfo(id);
        }

        /// <summary>
        /// 部门信息获取()
        /// </summary>       
        public List<User_Department> GetUserDepartment(string DepartmentName)
        {
            return UL1.GetUserDepartment(DepartmentName);
        }

        /// <summary>
        /// 职业信息获取
        /// </summary>
        /// <returns></returns>
       public List<User_Position> GetUserPostition(string Title)
        {
            return UL1.GetUserPosition(Title);
        }

        /// <summary>
        /// 用户信息获取
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public IEnumerable<object> GetUserList(string DName, string RName, string FName, string UName, string Phone, string NumberID)
        {
            return UL1.GetUserList(DName,RName,FName,UName,Phone,NumberID);
        }

        /// <summary>
        /// 在线用户获取
        /// </summary>
        /// <returns></returns>
        public IEnumerable<object> GetOnLineList(string Name)
        {
            return UL1.GetOnLineList(Name);
        }

        /// <summary>
        /// 类型获取
        /// </summary>
        /// <returns></returns>
        public Dictionary<string,object> GetTypeList()
        {
            Dictionary<string, object> dt = new Dictionary<string, object>()
           {
               {"UserDepartment",UL1.GetMyModels<User_Department>()},
               {"UserPosition",UL1.GetMyModels<User_Position>()},
               {"RoleName",UL1.GetMyModels<Role_Name>() }
           };
            return dt;
        }

        /// <summary>
        /// 添加和修改用户管理
        /// </summary>
        public bool UpdateUserList(User_List u,string type,int pk_User)
        {
            UL1.UpdateUserList(u, type, pk_User);
            return UL1.Savechanges();
        }
        /// <summary>
        /// 删除用户
        /// </summary>
        /// <param name="l"></param>
        /// <returns></returns>
        public bool DeleteUserList(User_List l)
        {
            UL1.DeleteUserList(l);
            return UL1.SaveChanges();
        }

        /// <summary>
        /// 添加，修改职位管理
        /// </summary>
        /// <param name="p"></param>
        /// <param name="type"></param>
        /// <returns></returns>
        public bool UpdatePosition(User_Position p,string type,int pk_User)
        {
            UL1.UpdatePosition(p, type,pk_User);
            return UL1.Savechanges();
        }
        /// <summary>
        /// 删除职业
        /// </summary>
        /// <param name="p"></param>
        /// <returns></returns>
        public bool DeletePosition(User_Position p)
        {
            UL1.DeletePosition(p);
            return UL1.Savechanges();
        }
        
        /// <summary>
        /// 添加，修改部门管理
        /// </summary>
        /// <param name="d"></param>
        /// <param name="type"></param>
        /// <returns></returns>
        public bool UpdateDepartment(User_Department d,string type,int pk_User)
        {
            UL1.UpdateDepartment(d, type, pk_User);
            return UL1.Savechanges();
        }

        /// <summary>
        /// 删除部门
        /// </summary>
        /// <param name="d"></param>
        /// <returns></returns>
        public bool DeleteDepartment(User_Department d)
        {
            UL1.DeleteDepaerment(d);
            return UL1.Savechanges();
        }

        public override void SetDal()
        {
            Dal = IUserList;
        }
    }
}
